package com.shadowtorcher.stdisk.logic;

import com.shadowtorcher.soulknife.SoulKnifeDB;
import com.shadowtorcher.soulknife.exception.BeanConfigErrorException;
import com.shadowtorcher.stdisk.bean.LogicFileBean;
import com.shadowtorcher.stdisk.bean.SharedFileBean;
import com.shadowtorcher.stdisk.util.StaticUtils;

import java.sql.SQLException;

public class FileShare {
	private String logicfileid;
	//将文件存入分享表
	public void share(String logicfileid){
		String code=StaticUtils.generatorShareCode();
		try {
            if (SoulKnifeDB.selectWhere("LogicFileID = ?", logicfileid).setClass(SharedFileBean.class).isEmpty()) {
                SharedFileBean sharedfilebean = new SharedFileBean();
                this.logicfileid = logicfileid;
                sharedfilebean.setCovfefe(0);
                sharedfilebean.setLogicFileID(logicfileid);
                sharedfilebean.setSharedFileID(logicfileid);
                sharedfilebean.setUrl(code);
                sharedfilebean.save();
            }
        } catch (BeanConfigErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LogicFileBean logicfile;
		try {
			logicfile = SoulKnifeDB.selectWhere("LogicFileID = ?", logicfileid).setClass(LogicFileBean.class).get(0);
			logicfile.setPublic(1);
			SoulKnifeDB.updateWhere(logicfile, "LogicFileID=?", logicfileid).setClass(LogicFileBean.class);
		} catch (BeanConfigErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
}
